//
//  ZYCStudentLeaveDetailCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/8/23.
//

#import "ZYCStudentLeaveDetailCell.h"
#import "ZYCLeaveRecordDetailModel.h"
#import "ZYCCollectionImageCell.h"

@interface ZYCStudentLeaveDetailCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *line;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@property (nonatomic, strong) NSArray *dataSource;

@end
@implementation ZYCStudentLeaveDetailCell

- (void)setModel:(ZYCLeaveRecordDetailModel *)model{
    _model = model;
    _contentLabel.text = model.leaveContent;
    self.dataSource =  model.files;
    [self.collectionView reloadData];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataSource.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ZYCCollectionImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([ZYCCollectionImageCell class]) forIndexPath:indexPath];
    cell.fileModel = self.dataSource[indexPath.item];
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.line];
        [self.contentView addSubview:self.contentLabel];
        [self.contentView addSubview:self.collectionView];

        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(self.contentView).offset(14.0f);
        }];

        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15.0f);
            make.right.equalTo(self.contentView).offset(-15.0f);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(15.0f);
            make.height.mas_equalTo(1.0f);
        }];
        
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(14.0f);
            make.right.equalTo(self.contentView).offset(-14.0f);
            make.top.equalTo(self.line.mas_bottom).offset(16.0f);
        }];
        
        [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(14.0f);
            make.right.equalTo(self.contentView).offset(-14.0f);
            make.top.equalTo(self.contentLabel.mas_bottom).offset(16.0f);
            make.height.mas_equalTo(120.0f);
        }];
    }
    return self;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel =   [UILabel LabelWithString:@"说明" Font:kCustomFont(@"PingFangSC-Light", 16.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _titleLabel;
}
- (UILabel *)contentLabel {
    if (!_contentLabel) {
        _contentLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 16.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
        _contentLabel.numberOfLines = 0;
    }
    return _contentLabel;
}

- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = HEX_RGB(@"#EBEBEB");
    }
    return _line;
}

-(UICollectionView *) collectionView{
    if (!_collectionView) {
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.layout];
        _collectionView.alwaysBounceVertical = YES;
        _collectionView.contentInset = UIEdgeInsetsMake(10, 0, 10, 0);
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([ZYCCollectionImageCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([ZYCCollectionImageCell class])];
    }
    return _collectionView;
}

-(UICollectionViewFlowLayout *) layout{
    if (!_layout) {
        _layout = [[UICollectionViewFlowLayout alloc] init];
        _layout.itemSize = CGSizeMake(98.0, 98.0f);
        _layout.minimumLineSpacing = 10;//行间距
        _layout.minimumInteritemSpacing = 0;//列间距
        _layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    }
    return _layout;
}

- (NSArray *)dataSource {
    if (!_dataSource) {
        _dataSource = [[NSArray alloc] init];
    }
    return _dataSource;
}
@end
